package node;

import parser.Parser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class CompUnitNode extends ASTNode {
    public final String name = "<CompUnit>";
    // CompUnit → {Decl} {FuncDef} MainFuncDef
    private List<DeclNode> declNodes = new ArrayList<>();
    private List<FuncDefNode> funcDefNodes = new ArrayList<>();
    private final MainFuncDefNode mainFuncDefNode;

    public CompUnitNode(List<DeclNode> declNode, List<FuncDefNode> funcDefNode, MainFuncDefNode mainFuncDefNode) {
        this.declNodes = declNode;
        this.funcDefNodes = funcDefNode;
        this.mainFuncDefNode = mainFuncDefNode;
    }

    @Override
    public void show() throws IOException {
        for (DeclNode declNode : declNodes) {
            declNode.show();
        }
        for (FuncDefNode funcDefNode : funcDefNodes) {
            funcDefNode.show();
        }
        if (mainFuncDefNode != null)
            mainFuncDefNode.show();
        Parser.parserWriter.write(name + "\n");
    }

}
